<template>
  <div class="content">
    <div class="have-record">
      <div
        class="info-list mainBack"
        @click="history(item)"
        v-for="(item, index) in bills"
        :key="index"
      >
        <ul>
          <li>
            <div class="invoice-content">
              <!-- 左侧信息 -->
              <div class="left-content">
                <div class="company-info">
                  <span class="customer-type">{{ item.custType | formStatus }}</span>
                  <span class="customer-name">{{ item.customer || '-' }}</span>
                </div>
                <div class="tax-info" v-if="item.socialCode">
                  <span class="label">税号：</span>
                  <span>{{ item.socialCode }}</span>
                </div>
                <div class="order-info">
                  <span class="label">订单号：</span>
                  <span>{{ item.orderNo || '-' }}</span>
                </div>
              </div>
              
              <!-- 右侧信息 -->
              <div class="right-content">
                <p class="amount">￥{{ formatAmount(item.openAmt) }}</p>
                <p class="status-text" :class="getStatusClass(item.vstatus)">
                  {{ getInvoiceStatus(item.vstatus, item.invoicetype) }}
                </p>
                <p class="date-text">申请日期: {{ item.applydate }}</p>
                <p v-if="item.failreason" class="error-text">{{ item.failreason }}</p>
              </div>
            </div>
          </li>
        </ul>
      </div>

      <div class="info-list mainBack" v-if="bills.length === 0">
        <ul>
          <li>
            <div class="col-1">暂无开票记录</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HistoryListView",
  data() {
    return {
      bills: []
    };
  },
  filters: {
    formStatus(value) {
      if (value === "1") {
        return '企业'
      } else if (value === "0") {
        return '个人'
      }
      return '未知'
    }
  },
  methods: {
    formatAmount(amount) {
      return amount ? Number(amount).toFixed(2) : '0.00'
    },
    history(item) {
      console.log('跳转参数:', { item});
      
      this.$router.push({ 
        path: "/HistoryView",
        query: { 
          VocNo: item.txId,
          txNo: item.txNo
        }
      });
    },
    getInvoiceStatus(vstatus, invoicetype) {
      const type = invoicetype === "1" ? "数电专票" : "数电普票"
      let status = ""
      switch(vstatus) {
        case "0": status = "开具中"; break;
        case "1": status = "已开具"; break;
        case "2": status = "开具失败"; break;
        case "3": status = "红冲中"; break;
        case "4": status = "已红冲"; break;
        case "5": status = "红冲作废"; break;
        default: status = "未知状态";
      }
      return `${type}-${status}`
    },
    getList() {
      this.$apiClient({
        method: "get",
        url: "/invoice/queryMetalElecReceiptRecord"
      }).then(res => {
       
        if (res.data.data.returnCode === "90000") {
          this.bills = res.data.data.bills || [];
          console.log(this.bills)
        }
      }).catch(error => {
        console.error('获取列表失败:', error);
        this.bills = [];
      });
    },
    getStatusClass(vstatus) {
      switch(vstatus) {
        case "1": return 'status-success'  // 已开具
        case "2": return 'status-fail'     // 开具失败
        case "0": return 'status-process'  // 开具中
        case "3": return 'status-process'  // 红冲中
        case "4": return 'status-success'  // 已红冲
        case "5": return 'status-fail'     // 红冲作废
        default: return 'status-default'
      }
    }
  },
  mounted() {
    this.getList();
  }
};
</script>

<style  scoped>
  a, abbr, audio, b, body, button, canvas, dd, div, dl, dt, em, footer, form, h1, h2, h3, h4, h5, h6, header, html, i, iframe, img, input, label, li, mark, menu, nav, ol, option, p, ruby, s, section, select, span, table, tbody, td, textarea, tfoot, th, thead, time, tr, ul, video {
    margin: 0;
    padding: 0;
    border: 0;
    list-style: none;
    font: inherit;
    font-family: \\65B9\6B63\5170\4EAD\9ED1\7B80\4F53,PingFang,Helvetica Neue,Helvetica,STHeiTi,Arial,sans-serif;
  }

  .content {
    overflow: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    position: absolute;
    top: 0;
    bottom: 0;
    height: 100%;
    font-size: 4.2vw;
    color: #333;

  }
  .padding-r {
    padding-right: 2vw;
  }
  .col-33 {
    width: 60%;
    white-space: nowrap;
  }
  .demo-block {
    position: relative;
    height: 40%;
  }
  .mainBack {
    background: #fff;
  }
  .margin-t {
    margin-top: .2rem;
  }
  .padding-t {
    padding-top: .2rem;
  }
  .mainBack ol,ul{
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .info-list ul li {
    padding: 4vw 3vw;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 2vw;
    border-bottom: 1px solid #e8e8e8;
    position: relative;
    display: -webkit-box;
    overflow: hidden;
  }
  .info-list ul li label {
    display: block;
    min-width: 2rem;
  }
  .txt-align-r {
    text-align: right;
  }
  .col-1 {
    width: 40%;
    -webkit-box-flex: 1;
    text-align : left ;
    line-height: 4rem;

  }
  .mtmine-radio {
    overflow: hidden;
  }
  .flex-justify-align {
    display: -webkit-box;
    -webkit-box-pack: justify;
  }
  .flex-justify-align {
    -webkit-box-align: center;
  }
  .flex-end {
    display: -webkit-box;
    -webkit-box-align: center;
    -webkit-box-pack: end;
  }
  .txt-red {
    color: #c9161e;
  }
  .txt-weight {
    font-weight: 900;

  }
  .invoice-total{
    padding: 0 .2rem .2rem;
  }
  .txt-h3, h3, h4 {
    font-size: 2.32rem;
  }
  .invoice-type .mtmine-radio .mint-cell {
    margin-right: 0;
    min-height: 10.5rem;
    padding-left: 1.3rem;
  }
  .mint-cell-left {
    position: absolute;
    height: 100%;
    left: 0;
    -webkit-transform: translate3d(-100%,0,0);
    transform: translate3d(-100%,0,0);
  }
  .mtmine-radio .mint-radio-core {
    width: .4rem;
    height: .4rem;
  }
  .mtmine-radio .mint-radio-input:checked+.mint-radio-core {
    background-color: #c9161e;
    border-color: #c9161e;
  }

  .mtmine-radio .mint-radio-label {
    margin-left: 0;
    font-size: 1.58rem;
  }
  .info-list ul li input[type=text] {
    display: block;
    -webkit-box-flex: 1;
    font-size: 1.58rem;
  }
  .info-list ul li input {
    border: none;
  }
  .mint-button.mint-button--large {
    line-height: 2.9rem;
    font-size: 1.3rem;
    width: 100%;
    color: #fff;
    background-color: #ccc;
    border-radius: 5.5rem;
  }
  .invoice-total {
    padding: 0 .2rem .2rem;
  }
  .padding-all {
    padding: .2rem;
    text-align :left;
  }
  .kaipiao{
    width :2.0rem;
    height :2.0rem;
  }
  .back-grey {
    background: #f8f8f8;
  }
  .mint-button--danger.is-plain {
    border: 1px solid #c9161e;
    color: #c9161e;
    background-color: #fff;
  }
  .mint-button--danger {
    background-color: #c9161e;
  }
  .mint-button {
    border-radius: 1.9rem;
    height: 4.6rem;
    display: block;
    font-size: 2.0rem;
    color :white;
  }
  .invoice-item {
    margin: 0 .2rem .2rem;
    border: 1px solid #e8e8e8;
    padding: .2rem;
    border-radius: .2rem;
  }
  .invoice-item:last-child {
    margin-bottom: 0;
  }
  .padding-b {
    padding-bottom: .2rem;
  }

  .border-b {
    border-bottom: 1px solid #e8e8e8;
  }

  .customer-type {
    font-size: 5vw;
    font-weight: bold;
    color: #333;
  }

  .amount {
    font-size: 6vw;
    font-weight: bold;
    color: #333;
  }

  .status-text {
    font-size: 3.8vw;
    color: #666;
    margin-top: 1vw;
    white-space: nowrap;
  }

  .date-text {
    font-size: 3.5vw;
    color: #999;
    margin-top: 1vw;
    white-space: nowrap;
  }

  .sub-text {
    font-size: 3.5vw;
    color: #ff4d4f;
    margin-top: 1vw;
  }

  .info-list ul li {
    padding: 4vw 3vw;
  }

  .col-1 {
    display: flex;
    align-items: center;
  }

  .demo-block {
    margin-bottom: 1vw;
  }

  .invoice-content {
    display: flex;
    justify-content: space-between;
    padding: 2vw 3vw;
    width: 100%;
    margin-left: -2vw;
  }

  .left-content {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 1.5vw;
    padding-right: 3vw;
  }

  .right-content {
    flex: 2;
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 1.5vw;
    padding-right: 2vw;
  }

  .company-info {
    display: flex;
    align-items: center;
    gap: 2vw;
    padding-left: 1vw;
  }

  .customer-type {
    font-size: 4.2vw;
    font-weight: bold;
    color: #333;
  }

  .customer-name {
    font-size: 4vw;
    color: #333;
  }

  .tax-info, .order-info {
    font-size: 3.5vw;
    color: #666;
    padding-left: 1vw;
  }

  .label {
    color: #999;
  }

  .amount {
    font-size: 5vw;
    font-weight: bold;
    color: #333;
  }

  .status-text {
    font-size: 3.8vw;
    white-space: nowrap;
  }

  .date-text {
    font-size: 3.5vw;
    color: #999;
  }

  .error-text {
    font-size: 3.5vw;
    color: #ff4d4f;
  }

  /* 状态颜色样式保持不变 */
  .status-success {
    color: #52c41a !important;
  }

  .status-fail {
    color: #ff4d4f !important;
  }

  .status-process {
    color: #1890ff !important;
  }

  .status-default {
    color: #666 !important;
  }
</style>
